package com.itcast.tanhuaserver.controller;

import com.itcast.tanhuaserver.service.PeachblossomService;
import com.itcast.tanhuaserver.vo.PeachblossomVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @PachageName: com.itcast.tanhuaserver.controller
 * @ClassName:
 * @Description: TODO
 * @Author: Hushi
 * @DateTime: 2021/3/211:48
 * @Version 1.0
 */
@RestController
@RequestMapping("peachblossom")
public class PeachblossomController {
    @Autowired
    private PeachblossomService peachblossomService;

    /**
     * 发送语音
     * @param file
     * @return
     */
    @PostMapping
    public ResponseEntity<PeachblossomVo> savePeachblossom(@RequestParam("soundFile")MultipartFile file){
        try {
            PeachblossomVo peachblossomVo = this.peachblossomService.savePeachblossom1(file);
            return ResponseEntity.ok(null);
        } catch (Exception e){
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }

    /**
     * 接收语音
     * @return
     */
    @GetMapping
    public ResponseEntity<PeachblossomVo> queryPeachblossom(){
        try {
            PeachblossomVo peachblossomVo = this.peachblossomService.queryPeachblossom();
            return ResponseEntity.ok(peachblossomVo);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }
}
